#!/bin/sh
branch="develop"
echo "默认分支： $branch"
echo "指定分支： $1 "
# 如果指定了分支，就切换为被指定的分支
if [ -n "$1" ]; then 
  echo "切换为指定的 $1 分支"
  branch=$1
fi


cd /neworiental/java_app/hermes

#mvn clean -Dmaven.study.skip
#mvn clean package -Dmaven.study.skip=true
git checkout $branch
git pull

mvn clean package -Dmaven.test.skip=true

# cd /neworiental/java_app/hermes/hermes-common
# mvn clean install -Dmaven.study.skip=true
# cd /neworiental/java_app/hermes/hermes-client
# mvn clean install -Dmaven.study.skip=true
# cd /neworiental/java_app/hermes/hermes-dao
# mvn clean install -Dmaven.study.skip=true
# cd /neworiental/java_app/hermes/hermes-biz
# mvn clean install -U -Dmaven.study.skip=true


# mvn clean install -pl hermes-web -am -Dmaven.study.skip

echo "=====cd /neworiental/java_app========"
cd /neworiental/java_app
if [ -e "herms_web.jar" ] && [ -e "/neworiental/java_app/hermes_web.jar" ];then
   echo "==================rm -rf hermes_web.jar=================="
   rm -rf /neworiental/java_app/hermes_web.jar;
   
fi 
cp /neworiental/java_app/hermes/hermes-web/target/hermes_web.jar /neworiental/java_app;

if [ -e "hermes_web.jar" ] && [ -e "/mnt/gfsdir/seal-fs-1/jarfile/hermes_web.jar" ]
then
  echo "==================rm -rf /mnt/gfsdir/seal-fs-1/jarfile/hermes_web.jar=================="
  rm -rf /mnt/gfsdir/seal-fs-1/jarfile/hermes_web.jar
fi

cp /neworiental/java_app/hermes/hermes-web/target/hermes_web.jar /mnt/gfsdir/seal-fs-1/jarfile;

while true
do
  ID=`ps -ef|grep "hermes_web.jar"|grep -v hermes.sh|grep -v "grep"|awk '{print $2}'`;
  echo $ID;
  if [ "$ID" = "" ]; then
    echo "==============break==============="
    break;
  else
    echo "==============$ID=============="
    for id in $ID
    do
      kill $id
      sleep 5
      echo "killing $id"
    done
    echo "---------------"
  fi
done
echo "======================start java service==================================="
nohup java -javaagent:/neworiental/skywalking/agent/skywalking-agent.jar -Dskywalking.agent.service_name=hermes  -jar -Xms1024m -Xmx1024m /neworiental/java_app/hermes_web.jar --spring.cloud.config.profile=pre --server.port=9999 --eureka.client.service-url.defaultZone=http://172.22.32.120:8761/eureka/ --spring.cloud.nacos.config.server-addr=172.26.128.186 --spring.cloud.nacos.config.namespace=seal-pre > hermes.log 2>&1 &
echo "==================================done=========================================="
#else
#echo "no restart"
#fi
